package com.meter.report.controller;

import com.meter.common.annotation.Log;
import com.meter.common.core.controller.BaseController;
import com.meter.common.core.domain.AjaxResult;
import com.meter.common.core.page.TableDataInfo;
import com.meter.common.enums.BusinessType;
import com.meter.common.utils.DateUtils;
import com.meter.common.utils.poi.ExcelUtil;
import com.meter.report.domain.ReportFlow;
import com.meter.report.service.IReportFlowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 热采集数据Controller
 * 
 * @author ruoyi
 * @date 2024-10-05
 */
@Controller
@RequestMapping("/report/flow")
public class ReportFlowController extends BaseController
{
    private String prefix = "report/flow";

    @Autowired
    private IReportFlowService reportFlowService;

    @GetMapping("/day")
    public String day(ModelMap mmap)
    {
        mmap.put("startTime", DateUtils.getMonth() + "-01");
        mmap.put("endTime", DateUtils.getDate());
        return prefix + "/day";
    }

    /**
     * 查询热采集数据列表
     */
    @PostMapping("/dayList")
    @ResponseBody
    public TableDataInfo dayList(ReportFlow reportFlow)
    {
        List<ReportFlow> list = reportFlowService.selectReportFlowByDay(reportFlow);
        return getDataTable(list);
    }

    /**
     * 导出热采集数据列表
     */
    @Log(title = "热量统计日报", businessType = BusinessType.EXPORT)
    @PostMapping("/dayExport")
    @ResponseBody
    public AjaxResult dayExport(ReportFlow reportFlow)
    {
        List<ReportFlow> list = reportFlowService.selectReportFlowByDay(reportFlow);
        ExcelUtil<ReportFlow> util = new ExcelUtil<ReportFlow>(ReportFlow.class);
        return util.exportExcel(list, "流量日报统计");
    }

    @GetMapping("/month")
    public String month(ModelMap mmap)
    {
        mmap.put("startTime", DateUtils.getYear() + "-01");
        mmap.put("endTime", DateUtils.getMonth());
        return prefix + "/month";
    }

    /**
     * 查询热采集数据列表
     */
    @PostMapping("/monthList")
    @ResponseBody
    public TableDataInfo list(ReportFlow reportFlow)
    {
        List<ReportFlow> list = reportFlowService.selectReportFlowByMonth(reportFlow);
        return getDataTable(list);
    }

    /**
     * 导出热采集数据列表
     */
    @Log(title = "热表月报统计数据", businessType = BusinessType.EXPORT)
    @PostMapping("/monthExport")
    @ResponseBody
    public AjaxResult monthExport(ReportFlow reportFlow)
    {
        List<ReportFlow> list = reportFlowService.selectReportFlowByMonth(reportFlow);
        ExcelUtil<ReportFlow> util = new ExcelUtil<ReportFlow>(ReportFlow.class);
        return util.exportExcel(list, "流量月报统计");
    }
}
